package com.poetize.plus.controller.admin;

import com.poetize.plus.entity.dto.FamilyDTO;
import com.poetize.plus.entity.vo.FamilyVO;
import com.poetize.plus.service.FamilyService;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author zuosy
 * @Date 2024/5/13 20:35
 **/
@Tag(name = "爱情小屋")
@RestController
@RequestMapping("/admin/family")
@RequiredArgsConstructor
public class FamilyController {

    private final FamilyService familyService;

    @PostMapping("/add")
    @Operation(summary = "新增")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> add(@RequestBody @Validated(Insert.class) FamilyDTO familyDTO){
        return R.ok(familyService.add(familyDTO));
    }


    @GetMapping
    @Operation(summary = "详情")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<FamilyVO> info(){
        return R.ok(familyService.info());
    }

    @PostMapping("/update")
    @Operation(summary = "修改")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> update(@RequestBody @Validated(Update.class) FamilyDTO familyDTO){
        return R.ok(familyService.update(familyDTO));
    }
}
